{% extends 'base.html' %}

{% block title %}添加备件 - 维修管理系统{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title mb-0">添加新备件</h4>
            </div>
            <div class="card-body">
                <form method="post">
                    {% csrf_token %}
                    
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label class="form-label">备件名称 <span class="text-danger">*</span></label>
                            <input type="text" name="name" class="form-control" required 
                                   placeholder="请输入备件名称">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">型号规格 <span class="text-danger">*</span></label>
                            <input type="text" name="model" class="form-control" required 
                                   placeholder="请输入型号规格">
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label class="form-label">SKU编号 <span class="text-danger">*</span></label>
                            <input type="text" name="part_number" class="form-control" required 
                                   placeholder="请输入唯一SKU编号">
                            <div class="form-text">SKU编号必须唯一，用于标识备件</div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">供应商编号</label>
                            <input type="text" name="supplier_part_number" class="form-control" 
                                   placeholder="供应商提供的编号">
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label class="form-label">分类 <span class="text-danger">*</span></label>
                            <select name="category" class="form-select" required>
                                <option value="">-- 选择分类 --</option>
                                {% for category in categories %}
                                <option value="{{ category.id }}">{{ category.name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">供应商</label>
                            <select name="supplier" class="form-select">
                                <option value="">-- 选择供应商 --</option>
                                {% for supplier in suppliers %}
                                <option value="{{ supplier.id }}">{{ supplier.name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-4">
                            <label class="form-label">单位 <span class="text-danger">*</span></label>
                            <select name="unit" class="form-select" required>
                                <option value="个">个</option>
                                <option value="只">只</option>
                                <option value="套">套</option>
                                <option value="米">米</option>
                                <option value="卷">卷</option>
                                <option value="包">包</option>
                                <option value="箱">箱</option>
                                <option value="台">台</option>
                                <option value="件">件</option>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">单价 (元) <span class="text-danger">*</span></label>
                            <input type="number" name="unit_price" class="form-control" step="0.01" min="0" required 
                                   placeholder="0.00">
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">状态 <span class="text-danger">*</span></label>
                            <select name="status" class="form-select" required>
                                <option value="active" selected>正常</option>
                                <option value="discontinued">停产</option>
                                <option value="obsolete">淘汰</option>
                            </select>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-4">
                            <label class="form-label">最低库存</label>
                            <input type="number" name="min_stock" class="form-control" min="0" 
                                   placeholder="0" value="0">
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">最高库存</label>
                            <input type="number" name="max_stock" class="form-control" min="0" 
                                   placeholder="0" value="0">
                            <div class="form-text">设为0表示不限制</div>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">初始库存</label>
                            <input type="number" name="initial_stock" class="form-control" min="0" 
                                   placeholder="0" value="0">
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">技术规格</label>
                        <textarea name="specifications" class="form-control" rows="3" 
                                  placeholder="请输入技术规格描述..."></textarea>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">备注</label>
                        <textarea name="notes" class="form-control" rows="2" 
                                  placeholder="请输入备注信息..."></textarea>
                    </div>

                    <div class="d-flex justify-content-between">
                        <a href="{% url 'spare_parts:sku_management' %}" class="btn btn-secondary">
                            <i class="bi bi-arrow-left"></i> 返回列表
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-check-circle"></i> 创建备件
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}
